package com.api.oa.controller;


import com.api.oa.model.entity.YQNewsType;
import com.api.oa.services.YQNewsTypeService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yq/yQNewsType")
public class YQNewsTypeController extends BaseController {

    @Autowired
    private YQNewsTypeService iYQNewsTypeService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public MyResult Add(@RequestBody YQNewsType entity) {
        try {
            return iYQNewsTypeService.add(entity) == 1 ? success(entity) : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/remove/{id}", method = RequestMethod.POST)
    public MyResult remove(@PathVariable Long id) {
        try {
            iYQNewsTypeService.remove(id);
            return success("删除成功!");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public MyResult update(@RequestBody YQNewsType entity) {
        try {
            return iYQNewsTypeService.update(entity) == 1 ? success("操作成功") : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MyResult list(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "20") Integer pageSize, @RequestParam(required = false) String keyWord) {
        try {
            return success(iYQNewsTypeService.list(keyWord, pageIndex, pageSize));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public MyResult all() {
        try {
            return success(iYQNewsTypeService.all());
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
    public MyResult one(@PathVariable Long id) {
        try {
            return success(id == null ? null : iYQNewsTypeService.one(id));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


}
